% vim: ts=4 sts=4 sw=4 et tw=75
% preamble here.

\documentclass[nofonts, oneside, fancyhdr]{ctexbook}

\usepackage{geometry}
\usepackage{fontspec}
\usepackage{xeCJK}
\usepackage{amssymb}
% for tikz
\usepackage{tikz}
% for varwidth
\usepackage{varwidth}
\usepackage{hyperref}
\usepackage{fancyhdr}
\usepackage{verbatim}
% for float's caption
\usepackage{caption}
% for exercise 
\usepackage{theorem}
% for varwidth
\usepackage{varwidth}
\usepackage{tikz}
% for format of contents
\usepackage{tocloft}
% for number of footnote 
\usepackage{pifont}
% 一页结束时, 脚注编号清零
\usepackage[perpage]{footmisc}
% summary 的边框
\usepackage{mdframed}
% 插图所需的宏包
\usepackage{graphicx}
% 
\usepackage[all, pdf]{xy}
% 边框
\usepackage{mdframed}
% 双栏排版
\usepackage{multicol}
% 表格单元格内换行
\usepackage{makecell}
\usepackage{listings}

\usepackage{pdfpages}
\usepackage{bookmark}

% 脚注编号带圈
\renewcommand\thefootnote{\ding{\numexpr171+\value{footnote}}}

% from package geometry
% 为边注加边框
\let\oldmarginpar=\marginpar
\renewcommand\marginpar[1]{%
    \oldmarginpar{\framebox{#1}}%
}
\geometry{%
    margin=1cm,
    marginparsep = 0.5cm,
    marginparwidth=1cm,
    top = 2.5cm,
    bottom = 2cm,
    outer = 2.0cm,
    inner = 2.0cm
}

\pagestyle{fancy}
\fancyhead[LE,RO]{\rightmark}
\fancyhead[LO,RE]{\leftmark}
\fancyfoot[C]{\thepage}

% from package hyperref
\hypersetup{
    bookmarksnumbered = true,
    pdftitle = {The AWK Programming Language},
    pdfcreator = {wuzhouhui250@gmail.com},
    pdfauthor = {Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger},
    pdfsubject = {awk programming},
    pdfkeywords = {awk, pattern scanning, text processing}
}

% from package fontspec and xeCJK
\setCJKmainfont{AR PL KaitiM GB}
\setCJKsansfont{AR PL KaitiM GB}
\setCJKmonofont{AR PL KaitiM GB}
\setmainfont{Century Schoolbook L}
\setsansfont{FreeSans}
% "Mapping={}" make quote symbol straight
\setmonofont[Mapping={}]{Courier 10 Pitch}

% the name of file or directory
\newcommand\filename[1]{\texttt{#1}}

% awk program, from package verbatim
\newenvironment{awkcode}%
{\verbatim}%
{\endverbatim}

% pattern for many situations
\newenvironment{pattern}%
{\begin{quotation}}%
{\end{quotation}}

% environment for summary
\newmdenv{summaryframe}
\newenvironment{summary}[1]
{
    \begin{summaryframe}
    \begin{center} \Large{#1} \end{center}%
}
{
    \end{summaryframe}
}

% term in English
\newcommand\term[1]{\textit{#1}}
% term in Chinese
\newcommand\cterm[1]{\textbf{#1}}

% subsection unnumbered
\CTEXsetup[number={}]{subsection}

% Looks like subsection's format, reference CTex manual ctex.pdf
\newcommand\pseudosubsec[1]{
    \vspace{3.25ex plus 1ex minus .2ex}
    \noindent\large\textbf{\phantom{占}#1}
    \vspace{1.5ex plus .2ex}
    \phantomsection
    \addcontentsline{toc}{subsection}{\protect\numberline{}#1}
}

% word that shows frequently
\newcommand\awk{\texttt{awk}}
\newcommand\print{\texttt{print}}
\newcommand\printf{\texttt{printf}}
\newcommand\nf{\texttt{NF}}
\newcommand\nr{\texttt{NR}}
\newcommand\AND{\texttt{\&\&}}
\newcommand\OR{\texttt{||}}
\newcommand\NOT{\texttt{!}}
\newcommand\BEGIN{\texttt{BEGIN}}
\newcommand\END{\texttt{END}}
\newcommand\length{\texttt{length}}
\newcommand\while{\texttt{while}}
\newcommand\for{\texttt{for}}
\newcommand\patact{\ \mbox{模式}\mbox{--}动作\ }
\newcommand\stmt{\textit{statements}}
\newcommand\expr{\textit{expression}}
\newcommand\regexpr{\textit{regular expression}}
\newcommand\pat{\textit{pattern}}
\newcommand\fs{\texttt{FS}}
\newcommand\OFS{\texttt{OFS}}
\newcommand\ctn{\texttt{continue}}
\newcommand\fmt{\textit{format}}

\theoremstyle{plain}
\theoremheaderfont{\bfseries}
\theorembodyfont{\normalfont}
\newtheorem{exercise}{习题}[chapter]
\newcommand\myexer{\textbf{习题\ }}

% 设置目录中 subsection 的缩进
\settowidth\cftsubsecindent{2em}
% 设置目录中 chapter 章节编号的宽度 (ctex 章节编号为中文, 需要特别注意).
% 参考 <<LaTeX 入门>>, 刘海洋 编著, 电子工业出版社, 2013.6
\settowidth\cftchapnumwidth{第十章} % 最宽的可能编号
\renewcommand\cftchapaftersnumb{\hspace{0.5em}} % 额外间距

\title{AWK 程序设计语言}
\author{Alfred V.Aho \and Brian W.Kernighan \and Peter J.Weinberger \and
    \url{https://github.com/wuzhouhui/awk}
}
